#pragma once
#include "../core.h"
#include "../singleton.h"

namespace qb{
	namespace base{
		class HeapAllocator;
		class S_CORE_EXPORT AllocatorInterface {
			HeapAllocator*	m_allocator;
			int				m_item_size;
		public:
			AllocatorInterface(int itemSize);
			~AllocatorInterface();
			void* Alloc(int bytes);
			void  Free(void* ptr, int bytes);
		};
		
		template<class T>
		class  AllocatorPool : public Singleton<AllocatorPool<T> > {
			AllocatorInterface	m_ai;
			int					m_size;
		public:
			static T* Alloc(){
				return AllocatorPool<T>::instance()->AllocImpl();
			}
			static void  Free(T* t){
				AllocatorPool<T>::instance()->FreeImpl(t);
			}
			static void  Register(const char* name);
			friend class Singleton<AllocatorPool<T> >;
		protected:
			AllocatorPool() :m_size(sizeof(T)), m_ai(sizeof(T))
			{

			}
			~AllocatorPool()
			{

			}
		protected:
			T* AllocImpl(){
				return (T*)m_ai.Alloc(sizeof(T));
			}
			void  FreeImpl(void* ptr)
			{
				m_ai.Free(ptr, sizeof(T));
			}
		};
	}//namespace base;
}//namespace ss;
